package neuralmusic.brain.module;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;


import uk.co.drpj.util.tweaks.Tweakable;
import uk.co.drpj.util.tweaks.TweakableDouble;

/**
 *   A layer extends a BasicModule.
 *   The spatial distribution of a layer is a 1D line.
 */

public class Layer extends BasicModule implements Serializable{

	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	//transient private TweakableDouble threshMod;

	// create input neurons
	// create the connections so we can fire them

	public Layer(String name, int size, Point p1, Point p2,
			NeuronParams pramIn, Brain brain, Collection<Tweakable> tweaks) {
		super(name);
		
//		threshMod = new TweakableDouble(tweaks, 0.0, 100.0, 1.0, 0.1, name
//				+ "Threshold");

		for (int i = 0; i < size; i++) {
			float fact1 = ((float) (i + 0.5)) / (size);
			float fact2 = (1.0f - fact1);
			Point p = new Point(p1.x * fact1 + fact2 * p2.x, p1.y * fact1
					+ fact2 * p2.y);
			Neuron n = new Neuron(p,  pramIn);
			neurons.add(n);	
		}

	}

	public void createInputConnections(float inputConnectWeight, Brain brain) {
		assert (inputs == null);
		inputs = new ArrayList<Connection>();
		for (Neuron n : neurons) {
			Connection c = brain.createConnection(null,n,inputConnectWeight);
			inputs.add(c);		
			brain.addConnection(c);
		}
	}

	public void createOutputConnections(float outputConnectWeight, Brain brain) {
		assert (outputs == null);
		outputs = new ArrayList<Connection>();
		for (Neuron n : neurons) {
			Connection c = brain.createConnection(n, null, outputConnectWeight);
			outputs.add(c);
		}
	}

}
